package leetcode.剑指offer.后40;

import leetcode.剑指offer.pojo.TreeNode;
import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/8/1 22:29
 * @description：https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/
 */
public class 剑指_54_二叉搜索树的第k大节点 {
    @Test
    public void test() {
        Solution solution = new Solution();
    }

    class Solution {
        int ans;
        int k;
        public int kthLargest(TreeNode root, int k) {
            this.k = k - 1;
            order(root);
            return ans;
        }

        private void order(TreeNode node) {
            if (node == null) return;
            order(node.right);
            if (k == 0) {
                ans = node.val;
                return;
            }
            order(node.left);
        }
    }

}
